package rysi.jpa;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.Date;
import java.util.Random;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import rysi.productos.modelo.Articulo;
import rysi.productos.oad.ArticuloJpaController;

/**
 *
 * @author jaguilar
 */
public class TestProductos {

    public static void main(String[] args) {
        EntityManagerFactory emf = 
                Persistence.createEntityManagerFactory("EjemploJPAPU");
        ArticuloJpaController articuloOad = new ArticuloJpaController(emf);
        
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
        String momento = df.format(new Date()).replaceAll("\\W*", "");
        Random rnd = new Random();
        
        Articulo art1 = new Articulo();
        art1.setNombre("Articulo-" + momento);
        art1.setDescripcion("Blablabla" + momento);
        art1.setPrecio(new BigDecimal(rnd.nextInt(1000)));
        articuloOad.create(art1);
        
        System.out.println(articuloOad.getArticuloCount() + " articulos");
    }
}





